<template>
  <div class="brand-product">
    <s-header :name="'品牌'"></s-header>
    <!-- 品牌组件 -->
    <Brand :brand="brandStore"></Brand>
    <!-- 商品列表 -->
    <div class="good">
      <header class="good-header">热门商品</header>
      <van-skeleton title :row="3" :loading="loading">
        <div class="good-box">
          <img class="empty-img" src="https://image-oss.dangaoss.cn/common/common_20241127150405_331.jpg" v-if="goodList.length===0">
          <div class="good-item" v-for="item in goodList" :key="item.id" @click="goToDetail(item)">
            <img :src="item.imagePath" alt="">
            <div class="good-desc">
              <div class="title">{{ item.title }}</div>
              <div class="brand">{{item.name}}</div>
              <div class="price">¥ {{ item.price }}</div>
            </div>
          </div>
        </div>
      </van-skeleton>
    </div>
  </div>
</template>

<script lang="ts" setup>
import sHeader from '@/components/SimpleHeader.vue'
import Brand from "@/components/Brand.vue";
import {useBrandStoreHook} from "@/stores/brand";
import {onMounted, ref} from "vue";
import {closeToast, showLoadingToast} from "vant";
import {fetchBrandGoodList} from "@/service/brand";
import {useRouter} from "vue-router";

const router = useRouter()
const brandStore = useBrandStoreHook()
const goodList = ref<any[]>([])
const loading = ref(false)
const goToDetail = (item) => {
  router.push({ path: `/product`, query: { id: item.id } })
}
const getGoodList = async () => {
  showLoadingToast({
    message: '加载中...',
    forbidClick: true
  })
  const res = await fetchBrandGoodList(brandStore.id, 1, 100)
  goodList.value = res.data.list || []
  loading.value = false
  closeToast()
}
onMounted(() => {
  getGoodList()
})
</script>

<style lang="less">
@import '../common/style/mixin';

.brand-product {
  .good {
    .good-header {
      background: #f9f9f9;
      height: 50px;
      line-height: 50px;
      text-align: center;
      color: @primary;
      font-size: 16px;
      font-weight: 500;
    }
    .good-box {
      display: flex;
      justify-content: flex-start;
      flex-wrap: wrap;
      .empty-img {
        width: 100%;
      }
      .good-item {
        box-sizing: border-box;
        width: 50%;
        border-bottom: 1PX solid #e9e9e9;
        padding: 10px 10px;
        img {
          display: block;
          width: 120px;
          height: 120px;
          border-radius: 12px;
          margin: 0 auto;
        }
        .good-desc {
          text-align: center;
          font-size: 14px;
          padding: 10px 0;
          .title {
            color: #222333;
          }
          .price {
            color: @primary;
          }
        }
        &:nth-child(2n + 1) {
          border-right: 1PX solid #e9e9e9;
        }
      }
    }
  }
}
</style>
